package com.my.code.testcode.lambda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 常用的函数是接口(SAM接口):
 * java.lang.Runnable: public void run();
 * java.lang.Comparable<T>: public int compareTo(T t)
 * java.util.Comparator<T>: public int compare(T t1,T t2)
 * java.lang.Iterable: public Iterator iterator()
 * lava.io.FileFilter: public boolean accept(File pathname)
 * <p>
 * java8建议,SAM接口使用@FunctionalInterface标注函数式接口
 */

public class FunctionInterface {


    @Test
    public void test() {
        List<Employee> employees = new ArrayList<>();

        employees.add(new Employee(1, "小李", 10000.00));
        employees.add(new Employee(2, "小张", 20000.00));

        employees.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                return 0;
            }
        });

        employees.sort(Comparator.comparingDouble(Employee::getSalary));

    }


}
